//
//  UserCommentListController.m
//  YongChuanTradingArea
//
//  Created by 李冰 on 2017/9/20.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "UserCommentListController.h"
#import "UserCommentListCell.h"
#import "UserCommentListModel.h"
static NSString * const UserCommentListCellIde = @"UserCommentListCellIde";

@interface UserCommentListController ()

@end

@implementation UserCommentListController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"评论详情";
    
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = kBgColor;
    self.tableView.separatorColor = kLineColor;
    self.tableView.estimatedRowHeight = 100;
    [self setupPageHeader:YES footer:YES];
    [self headerRefresh];
    [self.tableView registerNib:[UINib nibWithNibName:@"UserCommentListCell" bundle:nil] forCellReuseIdentifier:UserCommentListCellIde];
    
}

- (void)requestPageData:(void (^)(YCNetworkingStatusCode, NSArray *))statusBlock {
    
    if (![LBUserManage defaultManager].memberId)
    {
        [MBProgressHUD showMessageWithOutIcon:@"请登录后尝试"];
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        return;
    }
    
    NSString *userId = [LBUserManage defaultManager].memberId;
    NSString *pageIndex = [NSString stringWithFormat:@"%ld", self.pageIndex];
    NSString *pageSize = [NSString stringWithFormat:@"%ld", self.pageSize];
    NSString *storeId = self.store_id;
    NSString *goodsId = self.goods_id;
    NSString *keyWord = @"1";
//    userId={userId}&storeId={storeId}&goodsId={goodsId}&&keyWord={keyWord}&pageIndex={pageIndex}
    [LBNetworkingInstance requestGET:commentsList parameters:NSDictionaryOfVariableBindings(userId,pageIndex,pageSize,storeId,goodsId,keyWord) showHUD:YES success:^(id  _Nonnull responseObject, NSInteger code, NSString * _Nonnull message) {
        
        if (code == YCNetworkingStatusCodeSuccess || code == YCNetworkingStatusCodeNoneData)
        {
            NSArray *array = [NSArray yy_modelArrayWithClass:UserCommentListModel.class json:responseObject[@"Data"]];
            statusBlock(code, array);
            [self.tableView reloadData];
        }
        else
        {
            statusBlock(code, nil);
        }
        
        
    } failure:^(NSError * _Nonnull err) {
        statusBlock(YCNetworkingStatusCodeHTTPError, nil);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UserCommentListModel *model = self.dataSource[indexPath.item];
    UserCommentListCell *cell = [tableView dequeueReusableCellWithIdentifier:UserCommentListCellIde forIndexPath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
@end
